from rest_framework import serializers

from goods.models import GoodsVisitCount
from users.models import User


class UserSerializer(serializers.ModelSerializer):
    class Meta:
        model = User
        fields = ("id", "username", "mobile", "email", "password")
        extra_kwargs = {
            'username': {
                'max_length': 20,
                'min_length': 5
            },
            'password': {
                'write_only': True,
                'max_length': 20,
                'min_length': 8
            }
        }

    def create(self, validated_data):
        user = User.objects.create_user(**validated_data)
        return user
